package com.example.topic.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * ClassName:MessageService
 * Package:com.example.topic.service
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/8/11-18:37
 * @Version:v1.0
 */
@Service
@Slf4j
public class MessageService {

    @Value("${my.exchangeName}")
    private String exchangeName;

    @Value("${my.queueAName}")
    private String queueAName;

    @Value("${my.queueBName}")
    private String queueBName;

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void sendMsg() throws InterruptedException {
        Message message = MessageBuilder.withBody("TopicExchange".getBytes()).build();

        amqpTemplate.convertAndSend(exchangeName, "hello.world", message);
        log.info("第一条消息发送完成,发送时间为：{}",new Date());

        log.info("开始睡眠");
        Thread.sleep(3000);
        log.info("睡眠结束");

        amqpTemplate.convertAndSend(exchangeName,"lazy.orange.rabbit",message);
        log.info("第二条消息发送完成,发送时间为：{}",new Date());

    }

}
